Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fw 956 refactor on changes #28187

Closed
wants to merge 9 commits into from

Conversation

benlesh
Copy link
Contributor

@benlesh benlesh commented Jan 16, 2019

This change inverts the control over who is setting up onChanges to fire from the parent template to the component/directive definition itself. The idea is that the new NgOnChangesFeature will add a setInput function to the directive definition that is to be called when setting an input from a parent template. That setInput function will be composed to update a SimpleChanges object that is now stored at a known private property on the component instance.

Reverts most of the changes from the #27965 PR that moved control of onChanges into the parent template's instructions.

@benlesh benlesh requested review from a team as code owners January 16, 2019 17:39
@benlesh benlesh added target: major This PR is targeted for the next major release comp: ivy risk: low labels Jan 16, 2019
@ngbot ngbot bot added this to the needsTriage milestone Jan 16, 2019
@mary-poppins
Copy link

You can preview 9cff51c at https://pr28187-9cff51c.ngbuilds.io/.

@mary-poppins
Copy link

You can preview c39d3c7 at https://pr28187-c39d3c7.ngbuilds.io/.

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General approach looks good, but we need the tests turned on to verify

packages/upgrade/test/dynamic/upgrade_spec.ts Outdated Show resolved Hide resolved
packages/core/test/render3/ng_on_changes_feature_spec.ts Outdated Show resolved Hide resolved
@@ -81,13 +81,13 @@
"name": "NO_PARENT_INJECTOR"
},
{
"name": "NodeInjectorFactory"
"name": "NgOnChangesFeature"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems odd that we are bringing NgOnChangesFeature into hello_world. Why would that be the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suspect this is a bug with the how the compiler is identifying the presence of the feature and adding it. I think we can fix this in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer we get to the bottom of extra inclusion, unless it is blocking something. Fix up PR later tend to not happen.

packages/compiler/src/render3/view/api.ts Show resolved Hide resolved
packages/core/src/interface/lifecycle_hooks.ts Outdated Show resolved Hide resolved
@kara kara added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jan 16, 2019
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! 🎉

ngDevMode && assertDataInRange(lView, index);
const def = tView.data[index] as DirectiveDef<any>;
const setInput = def.setInput;
if (setInput) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intermediate assignment seems unnecessary, removing it avoids the !:

if (def.setInput) {
  def.setInput(instance, value, publicName, privateName);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an optimization to prevent it from being looked up twice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benlesh it would be, if the call didn't rely on this being the DirectiveDef (or we should use setInput.call(def, …). We are currently reading it twice already because of that.

function ngOnChangesSetInput<T>(
this: DirectiveDef<T>, instance: T, value: any, publicName: string, privateName: string): void {
const simpleChangesStore = getSimpleChangesStore(instance) ||
setSimpleChangesStore(instance, {previous: null, current: null});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems as if we can assign EMPTY_OBJ into previous here immediately, such that it is guaranteed to be present (the NgSimpleChangesStore.previous property may loose null from its type and the assignment of local var previous below can be inlined into the assignment of previousChange)

@mary-poppins
Copy link

You can preview 8c07bd4 at https://pr28187-8c07bd4.ngbuilds.io/.

@mary-poppins
Copy link

You can preview 00bc640 at https://pr28187-00bc640.ngbuilds.io/.

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kara kara removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jan 17, 2019
@benlesh benlesh added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Jan 18, 2019
@ngbot ngbot bot added the action: merge The PR is ready for merge by the caretaker label Jan 18, 2019
@ngbot
Copy link

ngbot bot commented Jan 18, 2019

I see that you just added the PR action: merge label, but the following checks are still failing:
    failure status "ci/circleci: integration_test" is failing
    pending status "google3" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@benlesh
Copy link
Contributor Author

benlesh commented Jan 18, 2019

@marclaval marclaval mentioned this pull request Jan 18, 2019
@alxhub
Copy link
Member

alxhub commented Jan 18, 2019

Note: missing reviews.

@@ -34,20 +34,14 @@ import {Directive, EmbeddedViewRef, Input, OnChanges, SimpleChange, SimpleChange
*/
@Directive({selector: '[ngTemplateOutlet]'})
export class NgTemplateOutlet implements OnChanges {
private _viewRef: EmbeddedViewRef<any>|null = null;
// TODO(issue/24571): remove '!'.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file appears to have been accidentally reverted when I reverted the other onChanges changes.

(changes changes changes)

@alxhub alxhub added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Jan 22, 2019
@benlesh benlesh added state: WIP and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Jan 22, 2019
- Wraps the NgOnChangesFeature in a factory such that no side effects occur in the module root
- Adds comments to ngInherit property on feature definition interface to help guide others not to make the same mistake
- Updates compiler to generate the feature properly after the change to it being a factory
- Updates appropriate tests
@benlesh
Copy link
Contributor Author

benlesh commented Jan 22, 2019

Adding one more bit of work to this to resolve FW-965, which is that the NgOnChangesFeature, even as it previously existed, was being included in the hello_world bundle, which makes no reference to it.

@benlesh
Copy link
Contributor Author

benlesh commented Jan 22, 2019

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

*
* NOTE: DO NOT SET IN ROOT OF MODULE! Doing so will result in tree-shakers/bundlers
* identifying the change as a side effect, and the feature will be included in
* every bundle.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for including this 👍

@benlesh benlesh added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed state: WIP labels Jan 22, 2019
@kara
Copy link
Contributor

kara commented Jan 22, 2019

merge assistance: no longer need public-API approval because the public API changes were reverted (no longer in this PR). Should be good with approval from @mhevery and i.

@alxhub alxhub closed this in 5552661 Jan 23, 2019
alxhub pushed a commit that referenced this pull request Jan 23, 2019
alxhub pushed a commit that referenced this pull request Jan 23, 2019
- Wraps the NgOnChangesFeature in a factory such that no side effects occur in the module root
- Adds comments to ngInherit property on feature definition interface to help guide others not to make the same mistake
- Updates compiler to generate the feature properly after the change to it being a factory
- Updates appropriate tests

PR Close #28187
vetom pushed a commit to vetom/angular that referenced this pull request Jan 31, 2019
- adds fixmeIvy annotation to tests that should remain updated so we can resolve those issues in the subsequent commits

PR Close angular#28187
vetom pushed a commit to vetom/angular that referenced this pull request Jan 31, 2019
vetom pushed a commit to vetom/angular that referenced this pull request Jan 31, 2019
…ar#28187)

- Wraps the NgOnChangesFeature in a factory such that no side effects occur in the module root
- Adds comments to ngInherit property on feature definition interface to help guide others not to make the same mistake
- Updates compiler to generate the feature properly after the change to it being a factory
- Updates appropriate tests

PR Close angular#28187
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note risk: low target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants